package org.codetranslators.tools.visualization;

import java.util.Vector;

import org.codetranslators.common.Node;

/**
 * Represents a level defined in a breadth first search.
 * @author shreesha123
 *
 */
public class BFSLevel {

	private Vector<Node> nodes;
	private Vector<Node[]> siblings;  // A pair of nodes that have a common parent
	
	public BFSLevel(){
		nodes = new Vector<Node>();
		siblings = new Vector<Node[]>();
	}
	
	public void addNode(Node node){
		nodes.addElement(node);
	}
	
	public Node getNodeAt(int i){
		return nodes.elementAt(i);
	}
	
	public boolean containsNode(Node node){
		return nodes.contains(node);
	}
	
	public boolean isEmpty(){
		return nodes.isEmpty();
	}
	
	public Vector<Node> getNodes(){
		return nodes;
	}
	
	public void addSiblings(Node leftNode, Node rightNode){
		Node sibs[] = new Node[2];
		sibs[0] = leftNode;
		sibs[1] = rightNode;
		siblings.addElement(sibs);
		
		addNode(leftNode);
		addNode(rightNode);
	}
	
	public int getIndexOfNode(Node node){
		for(int i = 0; i < nodes.size(); i++){
			Node nd = nodes.elementAt(i);
			if(node == nd) return i;
		}
		return -1;  // Level does not contain the node
	}
}
